﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniCT.LinkShareWpf.Interface;

namespace UniCT.LinkShareWpf.CommunicationChannel
{
    public class Client
    {
        IContract _client;
        Channel _chan;

        public Client(Uri target)
        {
           
            _chan = new Channel(target);
            _client = _chan.Client;
        }


        public long PingRequest()
        {
            try
            {
                Console.WriteLine("Client, sto provando a pingare");
                long ticks = _client.Ping(Environment.TickCount);
                long ping = Environment.TickCount - ticks;
                _chan.Dispose();
                Console.WriteLine("Client,ho finito di pingare.");
                return ping;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                _chan.Dispose();
                return -1;
            }
            
        }

        public void SingleRequest(NetFilter netFilter)
        {
            try
            {

                Console.WriteLine("Client, Episodio"+netFilter.EpisodeN +" Stagione "+netFilter.SeasonN);
                Console.WriteLine("Client, sto provando a inviare il netFilter");
                _client.SearchRequest(netFilter);
                Console.WriteLine("Client, ho inviato il netFilter");
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }

        public void SendResourceRequest(NetResource netResource)
        {
            
            try
            {

                Console.WriteLine("Client, sto provando ad inviare la netResource");
                Console.WriteLine("Client, la netResource ha Sender(DOVREI ESSERE IO): "+netResource.Sender.ToString());
                _client.SendResource(netResource);
                Console.WriteLine("Client, ho inviato il netResource");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


        }




    }



    
}
